package com.ruoyi.sys.security.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sys.security.domain.TbPatrollingPersonnel;
import com.ruoyi.sys.security.service.ITbPatrollingPersonnelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡更人员Controller
 * 
 * @author iuxin
 * @date 2022-05-25
 */
@RestController
@RequestMapping("/electronicPatrolling/personnel")
public class TbPatrollingPersonnelController extends BaseController
{
    @Autowired
    private ITbPatrollingPersonnelService tbPatrollingPersonnelService;

    /**
     * 查询巡更人员列表
     */
    @PreAuthorize("@ss.hasPermi('electronicPatrolling:personnel:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbPatrollingPersonnel tbPatrollingPersonnel)
    {
        startPage();
        List<TbPatrollingPersonnel> list = tbPatrollingPersonnelService.selectTbPatrollingPersonnelList(tbPatrollingPersonnel);
        return getDataTable(list);
    }

    /**
     * 导出巡更人员列表
     */
    @PreAuthorize("@ss.hasPermi('electronicPatrolling:personnel:export')")
    @Log(title = "巡更人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbPatrollingPersonnel tbPatrollingPersonnel)
    {
        List<TbPatrollingPersonnel> list = tbPatrollingPersonnelService.selectTbPatrollingPersonnelList(tbPatrollingPersonnel);
        ExcelUtil<TbPatrollingPersonnel> util = new ExcelUtil<TbPatrollingPersonnel>(TbPatrollingPersonnel.class);
        util.exportExcel(response, list, "巡更人员数据");
    }

    /**
     * 获取巡更人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('electronicPatrolling:personnel:query')")
    @GetMapping(value = "/{ppId}")
    public AjaxResult getInfo(@PathVariable("ppId") Long ppId)
    {
        return AjaxResult.success(tbPatrollingPersonnelService.selectTbPatrollingPersonnelByPpId(ppId));
    }

    /**
     * 新增巡更人员
     */
    @PreAuthorize("@ss.hasPermi('electronicPatrolling:personnel:add')")
    @Log(title = "巡更人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbPatrollingPersonnel tbPatrollingPersonnel)
    {
        return toAjax(tbPatrollingPersonnelService.insertTbPatrollingPersonnel(tbPatrollingPersonnel));
    }

    /**
     * 修改巡更人员
     */
    @PreAuthorize("@ss.hasPermi('electronicPatrolling:personnel:edit')")
    @Log(title = "巡更人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbPatrollingPersonnel tbPatrollingPersonnel)
    {
        return toAjax(tbPatrollingPersonnelService.updateTbPatrollingPersonnel(tbPatrollingPersonnel));
    }

    /**
     * 删除巡更人员
     */
    @PreAuthorize("@ss.hasPermi('electronicPatrolling:personnel:remove')")
    @Log(title = "巡更人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ppIds}")
    public AjaxResult remove(@PathVariable Long[] ppIds)
    {
        return toAjax(tbPatrollingPersonnelService.deleteTbPatrollingPersonnelByPpIds(ppIds));
    }
}
